﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using CID.Tests.Support;
using CID.Domain.Development;
using CID.Domain.Operations;
using CID.Execution.Controller.Support;

namespace CID.Execution.Controller.Tests.Support
{
    [TestFixture]
    class AffectedVersionsResolverTests : BaseControllerTests
    {
        private IRelease release;
        private IEnvironment targetEnvironment;

        public override void SetUp()
        {
            base.SetUp();
            release = DevelopmentData.ActiveRelease;
            targetEnvironment = OperationsData.Environment;
        }

        [Test]
        public void Test_GetAffectedVersions_ShouldIncludeAllDependantVersionsOnTheReleaseVersions()
        {
            var affectedVersionsResolver = new AffectedVersionsResolver(release, targetEnvironment);

            var result = affectedVersionsResolver.GetAffectedVersions();

            Assert.AreEqual(release, affectedVersionsResolver.Release);
            Assert.AreEqual(targetEnvironment, affectedVersionsResolver.Environment);
            CollectionAssert.IsSubsetOf(release.Versions, result);
            CollectionAssert.Contains(result, DevelopmentData.Components[3].Versions.First());
            CollectionAssert.Contains(result, DevelopmentData.Components[5].Versions.First());
            CollectionAssert.Contains(result, DevelopmentData.Components[6].Versions.First());
            CollectionAssert.DoesNotContain(result, DevelopmentData.Components[4].Versions.First());
        }
    }
}
